<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['worker']=$this->model('model')->checkworker();
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$status=intval($_RQ['status']);
	$return['list']=array();
	$return['params']=array('status'=>$status);
	$month = date('Y-m',strtotime('-1 month'));
	$lastdaytime = $daytime-24*3600;
	$data['inallnum']=pdo_count('jy_shopworker_feelog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']));
	$data['inall']=pdo_getsum('jy_shopworker_feelog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']),'fee');
	$data['inday']=pdo_getsum('jy_shopworker_feelog',array('status'=>1,'workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid'],'month'=>$month),'fee');
	$return['group2']=pdo_get('jy_shopworker_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$return['worker']['group2id']));
	$return['group2']['shifeeset']=json_decode($return['group2']['shifeeset'],true);
	$return['group2']['feeset']=json_decode($return['group2']['feeset'],true);
	$return['worker']['feeinfo']=$return['worker']['status']==2?$return['group2']['feeset']:$return['group2']['shifeeset'];
	$return['data']=$data;
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
	$return['member']=$member;
	$return['psize']=20;
	set_html('title','薪资记录');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('workerid'=>$return['worker']['id'],'uniacid'=>$_SESSION['uniacid']);
	$params['status']=intval($_RQ['status']);
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=pdo_getlist('jy_shopworker_feelog',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['groupidtitle']=pdo_getcolumn('jy_shopworker_group',array('id'=>$item['groupid'],'uniacid'=>$_SESSION['uniacid']),'title');
		$item['group2idtitle']=pdo_getcolumn('jy_shopworker_group',array('id'=>$item['group2id'],'uniacid'=>$_SESSION['uniacid']),'title');
		$item['statustitle']=$this->orderlog_status[$item['status']];	
		$item['feeinfo']=json_decode($item['feeinfo'],true);
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
	}
	exi($list);
}
if($_RQ['op']=='kaoqingday'){
	if($_RQ['id']){
		if(!$_RQ['kaoqingday']){
			exi('请填写当月真实考勤天数！','error');
		}
		if($_RQ['kaoqingday']<1 || $_RQ['kaoqingday']>30){
			exi('请填写当月真实考勤天数！','error');
		}
		$item=pdo_get('jy_shopworker_feelog',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$feeinfo=json_decode($item['feeinfo'],true);
		$feeinfo=$this->model('model')->getfee($feeinfo,$item);
		$data=array(
			'kaoqingday'=>$_RQ['kaoqingday'],
			'fee'=>$feeinfo['newfee'],
			'payfee'=>$feeinfo['newpayfee'],
			'feeinfo'=>ijson_encode($feeinfo),
			'status'=>1,
		);
		pdo_update('jy_shopworker_feelog',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('操作成功！','','/feelog/');
	}else{
		exi('该薪资表不存在，请重新选择','error');
	}
}
?>